home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / Mandlebrot / Mandlebrot Folder / DrawMandel881.c < prev    next >
Text File  |  1990-05-07  |  6KB  |  240 lines

  1. /* *********************************************************************************
  2.      
  3.       FILE:            DrawMandel881.c
  4.       
  5.      DESCRIPTION:    DrawMandel is the main loop.  Picks a color using the value 
  6.                      calculated by calcMandel to index into the system CLUT.  
  7.                      Then uses the toolbox call RGBForeColor to set the line color 
  8.                      and finally a call to LineTo.  This is the 68881 version of 
  9.                      DrawMandel. Uses in-line assembly code to perform the 'calcMandel' 
  10.                      function (return a value for the color lookup at each point
  11.                     in the field).
  12.                     
  13.      AUTHOR:        Bruce E. Gladstone
  14.      
  15.      Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  16.      
  17.      Revision History:
  18.      ============================================================
  19.      5/1/90    - Release to Compuserve
  20.      ============================================================
  21.      
  22.      COMMENTS:
  23.      
  24.      None. 
  25.  
  26.    ******************************************************************************** */        
  27.  
  28. #include <stdio.h> 
  29. #include <MacTypes.h> 
  30. #include <WindowMgr.h>
  31. #include <MenuMgr.h>
  32. #include <EventMgr.h>
  33. #include <ToolboxUtil.h> 
  34. #include <ControlMgr.h>
  35. #include <color.h>
  36. #include <colortoolbox.h>
  37. #include "Mandelbrot.h"
  38.  
  39. /* ---------------------------- Global Variables ---------------------------------- */
  40.  
  41. extern int                colorQD;
  42. extern int                quitFlag;
  43. extern int                linearFlag;
  44. extern int                custPict;
  45. extern int                numColorBits;
  46. extern int                numColors, brushSize;
  47. extern int                limit;
  48. extern int                n;
  49. extern long                startTime, now;
  50. extern float            res;
  51. extern float            centx, centy;
  52. extern float            xmin, xmax, ymin, ymax;
  53. extern float            delx, dely;
  54.  
  55. /* ---------------------------- Global MacTypes ----------------------------------- */
  56.  
  57. extern Str255            str;
  58. extern CTabHandle        myColorHandle;
  59. extern RGBColor            aColor;
  60. extern Rect                myRect, dragRect;
  61. extern WindowPtr        aboutWindow;        
  62. extern MenuHandle        appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
  63. extern WindowPtr        myWindow;
  64.  
  65. /* ---------------------------  Local Prototypes  --------------------------------- */
  66.  
  67. void drawMandel ( void );
  68. int calcMandel ( float, float );
  69. int eventCheck ( void );
  70. void updateMenus ( void );
  71.  
  72.  
  73. /* --------------------------------------------------------------------------------
  74.     drawMandel - 5/01/90 beg
  75.    -------------------------------------------------------------------------------- */
  76. void
  77. drawMandel()
  78. {
  79.     int        n;
  80.     long    nx, ny;
  81.     long    xres, yres;
  82.     float    x, y, del;
  83.     Rect    aRect;
  84.     
  85.     int        eventResult;
  86.     
  87.     myRect = (*myWindow).portRect;
  88.     xres = myRect.right;
  89.     yres = myRect.bottom;
  90.     xmin = centx - res;
  91.     xmax = centx + res;
  92.     ymin = centy - res;
  93.     ymax = centy + res;
  94.     
  95.     delx = ( xmax - xmin )/( xres+1 );
  96.     dely = ( ymax - ymin )/( yres+1 );
  97.     if ( delx > dely )
  98.     {
  99.         dely = delx;
  100.     }
  101.     else 
  102.     {
  103.         delx = dely;
  104.     }
  105.     PenSize ( brushSize , brushSize );        
  106.     del = delx*brushSize;
  107.     y = ymin;
  108.     ny = 0;
  109.     nx = 0;
  110.     while ( ny < ( yres - 1 ))    
  111.     {
  112.         x  = xmin;
  113.         nx = 0;
  114.         while ( nx < ( xres - 1 ))
  115.         {    
  116.         asm    {
  117.                 ;==========================================================    
  118.                 ;    The following is a 68881 assembly version of calcMandel
  119.                 ;    The register assigments are:
  120.                 ;        zreal    FP1
  121.                 ;        zimag    FP2
  122.                 ;        zr2        FP3
  123.                 ;        zi2        FP4
  124.                 ;        zreal1    FP5
  125.                 ;        zreal2    FP6
  126.                 ;        creal    8(A6)
  127.                 ;        cimag    20(A6)
  128.                 ;        count    D7
  129.                 ;==========================================================
  130.                                                 ;
  131.                 fmove.s     (x),fp1                ;    zreal        
  132.                 fmove.s        (y),fp2                ;    zimag
  133.                 fmove.s        #100.0,fp5            ;    zreal1
  134.                 fmove.s        #200.0,fp6            ;    zreal2
  135.                 moveq        #1,d7                ;
  136.                 bra            @lptest                ;
  137.             loop:                                ;
  138.                 fmove.x        fp1,fp3                ;    zr2 = zreal * zreal
  139.                 fmul.x        fp1,fp3                ;
  140.                 fmove.x        fp2,fp4                ;    zi2 = zimag * zimag
  141.                 fmul.x        fp2,fp4                ;
  142.                 fmove.x        fp3,fp0                ;    if (( zr2 + zi2 ) > 4.0 ) break
  143.                 fadd.x        fp4,fp0                ;
  144.                 fcmp.s        #4.0,fp0            ;
  145.                 fbgt        @exit                ;
  146.                 fmul.s        #2.0,fp2            ;    zimag = 2*zreal*zimag+cimag
  147.                 fmul.x        fp1,fp2                ;
  148.                 fadd.s        (y),fp2                ;
  149.                 fmove.x        fp3,fp1                ;    zreal = zr2 - zi2 + creal;
  150.                 fsub.x        fp4,fp1                ;
  151.                 fadd.s        (x),fp1                ;
  152.                 fcmp.x        fp6,fp1                ;    if ( zreal == zreal2 )
  153.                 fbne        @nobreak            ;
  154.                 clr.w        d7                    ;    count = 0
  155.                 bra            @exit                ;
  156.             nobreak:                            ;
  157.                 fmove.x        fp5,fp6                ;    zreal2 = zreal1
  158.                 fmove.x        fp1,fp5                ;    zreal1 = zreal
  159.             lptest:                                ;
  160.                 addq.w        #1,d7                ;    count++
  161.                 cmp.w        (limit),d7            ;
  162.                 ble            @loop                ;    continue
  163.             exit:                                ;
  164.                 move.w        d7,*n                ;    put count in n
  165.                                                 ;
  166.             }  /* end assembly version of calcMandel */
  167.             
  168.             if ( colorQD && (numColorBits > 2 ))        /* color version */
  169.             {
  170.                 if ( linearFlag )
  171.                 {
  172.                     if (( n == 0 ) || ( n >= limit ))
  173.                     {
  174.                         n = numColors - 1;
  175.                     }
  176.                     else
  177.                     {
  178.                         n = n * numColors / limit;
  179.                     }
  180.                 }
  181.                 else
  182.                 {
  183.                     if (( n == 0 ) || ( n >= limit ))
  184.                     {
  185.                         n = numColors - 1;
  186.                     }
  187.                     else
  188.                     {
  189.                         n = n % numColors;
  190.                     }
  191.                 }
  192.                 aColor = (**myColorHandle).ctTable[n].rgb;
  193.                 RGBForeColor ( &aColor );
  194.                 LineTo ( nx, ny ); 
  195.             }
  196.             else                                /* black and white version */
  197.             {
  198.                 if (( n == 0 ) || ( n >= 256 ))
  199.                 {
  200.                     PenPat( black );
  201.                 }
  202.                 else if ( n > 50 )
  203.                 {
  204.                     PenPat( dkGray );
  205.                 }
  206.                 else if ( n > 10 )
  207.                 {
  208.                     PenPat( gray );
  209.                 }
  210.                 else if ( n > 2 )
  211.                 {
  212.                     PenPat( ltGray );
  213.                 }
  214.                 else
  215.                 {
  216.                     PenPat( white );
  217.                 }
  218.                 LineTo ( nx, ny );
  219.             }
  220.             if ( eventCheck () || quitFlag == TRUE ) goto breakOut;
  221.             nx = nx + brushSize;        /* end of nx loop */
  222.             x = x + del;
  223.         }
  224.         ny = ny + brushSize;            /* end of ny loop */
  225.         y = y + del;
  226.         MoveTo ( 0, ny );
  227.     }
  228.     breakOut:
  229.     {
  230.         MoveTo ( 0,0 );
  231.         now = ( TickCount() - startTime )/60;
  232.         updateMenus();            /*     Call update here so we can record time  */
  233.     }
  234. }    /* drawMandel()  */
  235.  
  236. /* ===============================  EOF  ==========================================
  237.     Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  238.    ================================================================================ */
  239.  
  240.